//
//  MusicTableViewCell.m
//  Project_B
//
//  Created by dllo on 15/12/1.
//  Copyright © 2015年 张闯. All rights reserved.
//

#import "MusicTableViewCell.h"
#import "MusicModel.h"
#import "UIImageView+WebCache.h"
#define CWIDTH self.contentView.frame.size.width
#define CHEIGHT self.contentView.frame.size.height
@interface MusicTableViewCell ()
@property (nonatomic, retain) UILabel *title;
@property (nonatomic, retain) UIImageView *image;
@property (nonatomic, retain) UILabel *nickname;
@property (nonatomic, retain) UILabel *duration;
@property (nonatomic, retain) UIImageView *play;
@property (nonatomic, retain) UIImageView *time;
@end

@implementation MusicTableViewCell


#pragma mark - 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.image = [[UIImageView alloc] init];
        [self.contentView addSubview:self.image];
        
        self.play = [[UIImageView alloc] init];
        [self.contentView addSubview:self.play];
        
        self.time = [[UIImageView alloc] init];
        [self.contentView addSubview:self.time];
        
        self.title = [[UILabel alloc] init];
        [self.contentView addSubview:self.title];
        
        self.nickname = [[UILabel alloc] init];
        [self.contentView addSubview:self.nickname];
        
        self.duration = [[UILabel alloc] init];
        [self.contentView addSubview:self.duration];

    }
    return self;
}

#pragma mark - 布局
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.image.frame = CGRectMake(10, 10, 50, 50);
    self.image.layer.cornerRadius = 25;
    self.image.clipsToBounds = YES;
    
    self.play.frame = CGRectMake(0, 0, 20, 20);
    self.play.center = self.image.center;
    self.play.image = [UIImage imageNamed:@"iconfont-bofang-2"];
    
    self.title.frame = CGRectMake(self.image.frame.size.width + 30, self.image.frame.origin.y, CWIDTH - 100, 16);
    self.title.font = [UIFont fontWithName:@"Helvetica" size:16];
    
    self.nickname.frame = CGRectMake(self.title.frame.origin.x, self.title.frame.origin.y + self.title.frame.size.height + 5, CWIDTH - 130, 14);
    self.nickname.font = [UIFont fontWithName:@"Helvetica" size:14];
    self.nickname.textColor = [UIColor grayColor];
    
    
    self.time.frame = CGRectMake(self.nickname.frame.origin.x, self.nickname.frame.origin.y + self.nickname.frame.size.height + 5, 12, 12);
    self.time.image = [UIImage imageNamed:@"shijian"];
    
    self.duration.frame = CGRectMake(self.time.frame.origin.x + 15, self.time.frame.origin.y, CWIDTH - 130, 12);
    self.duration.font = [UIFont fontWithName:@"Helvetica" size:12];
    self.duration.textColor = [UIColor grayColor];
}

#pragma mark - 赋值
- (void)setMusicModel:(MusicModel *)musicModel
{
    self.title.text = musicModel.title;
    self.nickname.text = [NSString stringWithFormat:@"by %@", musicModel.nickname];
    [self.image sd_setImageWithURL:[NSURL URLWithString:musicModel.coverMiddle]];
    self.duration.text = [NSString stringWithFormat:@"%02ld:%02ld", [musicModel.duration integerValue] / 60, [musicModel.duration integerValue] % 60 ];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
